package lambda.examples._02;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class App {

	List<Apple> getAppleList() {
		List<Apple> list = new ArrayList<Apple>();
		list.add(new Apple("green", 100));
		list.add(new Apple("red", 150));
		list.add(new Apple("green", 50));
		return list;
	}

	public void test() {
		List<Apple> list = getAppleList();
		list.sort(new Comparator<Apple>() {
			@Override
			public int compare(Apple a, Apple b) {
				return a.getWeight() > b.getWeight() ? 1 : (a.getWeight() < b.getWeight() ? -1 : 0);
			}
		});
		list.sort((a, b) -> a.getWeight() > b.getWeight() ? 1 : (a.getWeight() < b.getWeight() ? -1 : 0));
		list.forEach(System.out::println);
	}

}

class Apple {
	private String color;
	private int weight;

	public Apple(String color, int weight) {
		super();
		this.color = color;
		this.weight = weight;
	}

	@Override
	public String toString() {
		return "Apple [color=" + color + ", weight=" + weight + "]";
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}
}